/*package com.troila.cloud.simplify.service;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.troila.cloud.simplify.model.SAnswer;
import com.troila.cloud.simplify.model.Product;
import com.troila.cloud.simplify.repository.UserRepository;

@Service
@Transactional
public class UserService {

	@Autowired
	private UserRepository userRepository;


	public SAnswer save(SAnswer account) {
		
		return userRepository.save(account);
	}

	public Page<SAnswer> getUserList(SAnswer account, int page, int size,String userId) {
		Specification<SAnswer> specification = new Specification<SAnswer>() {
			@Override
			public Predicate toPredicate(Root<SAnswer> root,
					CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
				List<Predicate> predicates = new ArrayList<>();
				//用户ID
				predicates.add(criteriaBuilder.like(root.get("userId").as(String.class), "%"+userId+"%"));
				//是否管理员
				predicates.add(criteriaBuilder.equal(root.get("ifAdmin").as(String.class), "0"));
				return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
			}
		};
		
		//按状态查询
		Pageable pageable = new PageRequest(page, size);
		return userRepository.findAll(specification,pageable);
	}
	
	public List<SAnswer> getUserListByUserIdAndAcountId(String userId,String accountId,String productId){
		return userRepository.getUserListByUserIdAndAcountId(userId, accountId,productId);
	}
	
	public List<SAnswer> getUserInfoByUserIdAndPsdAndPdtId(String userId,String psd,String productId){
		return userRepository.getUserInfoByUserIdAndPsdAndPdtId(userId, psd,productId);
	}
	
	public List<SAnswer> getUserInfoByAccountIdAndPruductId(String accountId,String pruductId){
		return userRepository.getUserInfoByAccountIdAndPruductId(accountId, pruductId);
	}
	
	public List<SAnswer> getUserInfoByAccountId(String accountId){
		return userRepository.getUserInfoByAccountId(accountId);
	}
	
	
	public List<SAnswer> getUserInfoByUserIdAndPsdBg(String userId,String password,String ifAdmin){
		return userRepository.getUserInfoByUserIdAndPsdBg(userId, password,ifAdmin);
	}
	public void updateAccountStatusById(Integer status,Integer id) {
		userRepository.updateAccountStatusById(status,id);
	}
	
	public Page<SAnswer> getUserInfoByUserId(int page, int size,String UserId) {
		ExampleMatcher matcher = ExampleMatcher.matching()
				.withMatcher("userId", GenericPropertyMatchers.startsWith()) //姓名采用“开始匹配”的方式查询
                .withIgnorePaths("focus");  //忽略属性：是否关注。因为是基本类型，需要忽略掉
		SAnswer acc=new SAnswer();
		acc.setId(null);
		acc.setStatus(null);
		acc.setUserId(UserId);
		Example<SAnswer> ex=Example.of(acc, matcher);
		//按状态查询
		Pageable pageable = new PageRequest(page, size);
		return userRepository.findAll(ex,pageable);
	}
	
	public List<SAnswer> getUserInfoByUserId(String userId){
		return userRepository.getUserInfoByUserId(userId);
	}
	
	public Integer updateUserPsdByUserId(String password,String userId) {
		return userRepository.updateUserPsdByUserId(password,userId);
	}
	
	public List<SAnswer> findAll(String status){
		return userRepository.findAll(status);
	}
	
	public List<SAnswer> findAll(){
		return userRepository.findAll();
	}
}*/